package com.admin.education.models;

import com.admin.education.repositories.Identifiable;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "users")
@EntityListeners(AuditingEntityListener.class)
@Data
public class User  implements Serializable, Identifiable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @NotBlank
    @Column(name="user_name")
    @Length(max = 32)
    @NotNull
    private String userName;
    @NotBlank
    @Column(name="password")
    @Length(max = 32)
    @NotNull
    private String password;
    @Column(name = "open_id")
    @Length(max = 32)
    private String openId;
    @Column(name = "session_key")
    @Length(max = 128)
    private String sessionKey;
    @Column(name = "union_id")
    @Length(max = 128)
    private String unionId;
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy ="user")
    @JSONField(serialize=false)
    private List<UserInformation> userInformation;

}
